package com.jie.commonlib.widget

import android.view.Gravity
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils

/**
 * 封装Toast提示工具类
 */
class ToastHelper {

    companion object {

        private var mToastUtils: ToastUtils? = null

        /**
         * 获取单例ToastUtils对象
         */
        private fun getToastUtils() : ToastUtils{
            return mToastUtils?.let { it }
                ?: ToastUtils.make()
                    .setGravity(Gravity.CENTER, 0, 0)
                    .setMode(ToastUtils.MODE.DARK)
                    .apply {
                        mToastUtils = this
                    }
        }

        /**
         * 显示提示信息
         */
        fun show(msg : String?) {
            msg?.let {
                getToastUtils().run {
                    setDurationIsLong(it.length >= 15)
                    show(it)
                }
            }?:LogUtils.i("toast info is null")
        }
    }
}